<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/jsp/component/common.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>详细内容</title>
    <link rel="stylesheet" href="${frames}/css/lib/bootstrap.min.css" type="text/css" type="text/css">
    <link rel="stylesheet" href="${newframe}/css/base/base.css" type="text/css">
    <link rel="stylesheet" href="${newframe}/css/common.css" type="text/css">
    <link rel="stylesheet" href="${assets}/plugins/ztree/zTreeStyle/metro.css" type="text/css">
    <!--[if IE 8]>
    <link rel="stylesheet" href="${newframe}/css/base/IE8.css" type="text/css"/>
    <![endif]-->
    <%@ include file="/WEB-INF/jsp/component/commonBottom.jsp" %>
    <script src="${assets}/bootstrapValidator/js/bootstrapValidator.js"></script>
    <script src="${assets}/bootstrapValidator/js/language/zh_CN.js"></script>
    <script src="${assets}/plugins/ztree/jquery.ztree.all-3.5.min.js"></script>


    <script>
        $(document).ready(function () {

            $("input[type=checkbox]").each(function (i, e) {

                var servicesArray = [];
				
                <c:if test="${entity.roleList != null}">
                	servicesArray = ${entity.roleList};
	            </c:if>

                for (var i = 0; i < servicesArray.length; i++) {
                    if ($(this).val() == servicesArray[i].roleId) {
                        $(this).attr("checked",true);
                    }
                }
            });


            $('#myForm').bootstrapValidator({
                message: 'This value is not valid',
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    username: {
                        validators: {
                            notEmpty: true
                        }
                    },
                    status: {
                        validators: {
                            notEmpty: true
                        }
                    }

                }
            }).on('success.form.bv', function (e) {
                e.preventDefault();

                var _url = "";
                debugger;
                if ($("#id").val() == null || $("#id").val() == '') {
                    _url = '${URL_SYS_USER_LIST_ADD}';
                } else {
                    _url = '${URL_SYS_USER_LIST_UPDATE}';
                }

                $.ajax({
                    url: _url,
                    type: 'post',
                    data: $('#myForm').serialize(),
                    async: false, //默认为true 异步
                    dataType : 'json',
                    error: function (data) {
                        alert('error');
                    },
                    success: function (data) {
                        if(!data.success){
                        	alert(data.msg);
                        }else{
                            closeFrame();
                        }
                    }
                });

            });
        });
        //关闭并刷新
        function closeFrame() {
            window.parent.closeModal();
        }

        var setting = {

            check: {
                enable: true,
                chkStyle: "radio",
                radioType: "all"
            },

            data: {
                simpleData: {
                    enable: true
                }
            },
            callback: {
                beforeClick: beforeClick,
                onCheck: onCheck,
            }
        };

        var zNodes = ${organis};

        function setCheck() {
            var zTree = $.fn.zTree.getZTreeObj("organiTree");
            console.log(zTree);
        }
        function beforeClick(treeId, treeNode, clickFlag) {
            var zTree = $.fn.zTree.getZTreeObj("organiTree");
            zTree.checkNode(treeNode, !treeNode.checked, null, true);
            return false;
        }

        $(document).ready(function () {
            $.fn.zTree.init($("#organiTree"), setting, zNodes);
            setCheck();
        });
        function onCheck(e, treeId, treeNode) {
            if(treeNode.checked){
                $("#orgId").val(treeNode.id);
            }else {
                $("#orgId").val("");
            }

        }

    </script>
</head>
<body style="width: 98%">
<form id="myForm" class="form-horizontal" method="post">
    <input type="hidden" id="id" name="id" value="${entity.id}"/>
    <input type="hidden" id="orgId" name="orgId" value="${userOrgani.organiId}"/>
<%--    <input type="hidden" id="userKind" name="userKind" value="${entity.userKind}">--%>
    <div class="clearfix">
        <div class="form-group col-sm-6">
            <label class="col-sm-4 control-label">用户名</label>
            <div class="col-sm-8">
                <c:if test="${entity.id == null}">
                    <input type="text" id="username" name="username" class="form-control" value="${entity.username}">
                </c:if>
                <c:if test="${entity.id != null}">
                    <input type="text" id="username" name="username" class="form-control" value="${entity.username}" readonly="readonly">
                </c:if>

            </div>
        </div>
        <div class="form-group col-sm-6">
            <label class="col-sm-4 control-label">密码</label>
            <div class="col-sm-8">
                <input type="text" id="password" name="password" class="form-control">
            </div>
        </div>
        <div class="form-group col-sm-6">
            <label class="col-sm-4 control-label">姓名</label>
            <div class="col-sm-8">
                <input type="text" id="realName" name="realName" class="form-control" value="${entity.realName}">
            </div>
        </div>
        <div class="form-group col-sm-6">
            <label class="col-sm-4 control-label">手机号码</label>
            <div class="col-sm-8">
                <input type="text" id="mobile" name="mobile" class="form-control" value="${entity.mobile}">
            </div>
        </div>

        <div class="form-group col-sm-6">
            <label class="col-sm-4 control-label">用户类型</label>
            <div class="col-sm-8">
                <select id="userKind" name="userKind" class="form-control selectForm">
                    <medi:configOpt name="userKind" key="${entity.userKind}"/>
                </select>
            </div>
        </div>

        <div class="form-group col-sm-6 checkboxRight">
            <label class="col-sm-4 control-label">选择角色</label>
            <div class="col-sm-8">
                <c:forEach items="${roleList}" var="role" varStatus="status">
                    <label class="checkbox-inline">
                        <input type="checkbox" id="${role.roleId}" name="roleList[${status.index}].roleId" value="${role.roleId}">${role.roleName}
                    </label>
                </c:forEach>
            </div>
        </div>
        <div class="form-group col-sm-6">
            <label class="col-sm-4 control-label">用户状态</label>
            <div class="col-sm-8">
                <select id="status" name="status" class="form-control selectForm">
	                <medi:configOpt name="userStatus" key="${entity.status}"/>
                </select>
            </div>
        </div>
        <div class="form-group col-sm-6">
            <label class="col-sm-4 control-label">选择机构</label>
            <div class="col-sm-8">
                <ul id="organiTree" class="ztree"></ul>
            </div>
        </div>
</div>

    <div class="modal-footer" style="text-align: center;padding-bottom:70px; ">
        <button type="button" class="btn btn-default" data-dismiss="modal" id="closeModalButt"
                onclick="closeFrame()">关闭
        </button>
        <button type="submit" class="btn btn-primary">保存</button>
    </div>
</form>
</body>
</html>